﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class LoginFirst : Form
    {
        public LoginFirst()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string pass1, pass2;

            IntPtr unmanagedString = IntPtr.Zero;
            unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secureTextBox1.SecureText);
            pass1 = Marshal.PtrToStringUni(unmanagedString);
            Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);

            unmanagedString = IntPtr.Zero;
            unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secureTextBox2.SecureText);
            pass2 = Marshal.PtrToStringUni(unmanagedString);
            Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);

            if (pass1.CompareTo(pass2) == 0)
            {
                CompanyManager.lso.UserName = textBox1.Text;
                CompanyManager.lso.PassWord = pass1;

                Serializer s = new Serializer();
                s.SerializeObject(CompanyManager.passwordPath, CompanyManager.lso);
                MessageBox.Show(textBox1.Text + " :שם המשתמש" + "\n" + pass1 + " :סיסמא", "תזכורת",
                MessageBoxButtons.OK, MessageBoxIcon.Asterisk,
                MessageBoxDefaultButton.Button1);
                CompanyManager.enter = true;
                this.Close();
            }
            else
            {
                MessageBox.Show("יש לוודא שהסיסמא זהה בשני השדות", "שדות שונים",
                MessageBoxButtons.OK, MessageBoxIcon.Asterisk,
                MessageBoxDefaultButton.Button1); 
            }
        }
    }
}
